﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 特效效果
/// 有启动和关闭方法
/// </summary>
public class IEffect : MonoBehaviour {
    [SerializeField]
    protected bool PlayOnEnable = false;
    [SerializeField]
    protected bool StopOnDisable = false;
    /// <summary>
    /// 开启
    /// </summary>
    public virtual void Enable() { gameObject.SetActive(true); }
    /// <summary>
    /// 关闭
    /// </summary>
    public virtual void Disable() { gameObject.SetActive(false); }
    /// <summary>
    /// 开启一段时间再关闭
    /// </summary>
    /// <param name="dueTime"></param>
    public void Play(float dueTime)
    {
        Enable();
        Invoke("Disable",dueTime);
    }
    protected virtual void OnEnable()
    {
        if (PlayOnEnable) Enable();
    }
    protected virtual void OnDisable()
    {

        if (StopOnDisable) Disable();
    }
    /// <summary>
    /// 在pos播放一个粒子启动其上的所有粒子脚本
    /// </summary>
    /// <param name="type"></param>
    /// <param name="pos"></param>
    /// <param name="time"></param>
    public static IEffect[] PlayWhere(int type,Vector3 pos,float time)
    {
        IEffect[] es = Facade.Instance.Effects.Initiates<IEffect>(type, pos);
        foreach (var e in es)
        {
            e.Play(time);
        }
        return es;
    }
}
